package com.iflytek.hive.need8;


import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class GoodsAmountBean implements WritableComparable<GoodsAmountBean> {
    private String date;
    private String goodid;
    private double amount;
    public String getDate() {
        return date;
    }
    public void setDate(String date) {
        this.date = date;
    }
    public String getGoodid() {
        return goodid;
    }

    public void setGoodid(String goodid) {
        this.goodid = goodid;
    }

    public double getAmount() {
        return amount;
    }
    public void setAmount(double amount) {
        this.amount = amount;
    }

    public void set(String date,String goodid,double amount) {
        this.date = date;
        this.goodid = goodid;
        this.amount =amount;
    }

    @Override
    public int compareTo(GoodsAmountBean o) {
        int result = this.date.compareTo(o.date);
        if (result == 0) {
            return this.amount - o.getAmount() > 0 ? -1 : (this.amount - o.getAmount() < 0 ? 1 : 0);
        }
        return result;
    }


    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(date);
        out.writeUTF(goodid);
        out.writeDouble(amount);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        date = in.readUTF();
        goodid = in.readUTF();
        amount = in.readDouble();
    }
    @Override
    public String toString() {
        return date+","+goodid+","+amount;
    }
}
